package com.example.basic.web.controller.menu;

import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.menu.Menu;
import com.example.basic.web.service.menu.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "菜单管理", tags = {"菜单管理"})
@RestController
@RequestMapping("/api/v1/byg/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @Log(title = "系统菜单表", description = "新增或修改")
    @ApiOperation(value = "新增或修改", notes = "新增或修改")
    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@ApiParam(name = "menu", value = "模型", required = true) @RequestBody Menu menu) {
        return ResultGenerator.genSuccessResult(menuService.addOrUpdate(menu));
    }

    @Log(title = "系统菜单表", description = "详情")
    @ApiOperation(value = "详情", notes = "详情")
    @PostMapping("/detail")
    public Result detail(@ApiParam(name = "menuCode", value = "菜单编码") @RequestParam String menuCode) {
        return ResultGenerator.genSuccessResult(menuService.detail(menuCode));
    }

    @Log(title = "系统菜单表", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result delete(@ApiParam(name = "menuCode", value = "菜单编码") @RequestParam String menuCode ) {
        return ResultGenerator.genSuccessResult(menuService.delete(menuCode));
    }

    @Log(title = "系统菜单表", description = "启用/禁用")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    @PostMapping("/enableOrDisable")
    public Result enableOrDisable(@ApiParam(name = "menuCode", value = "菜单编码") @RequestParam String menuCode) {
        return ResultGenerator.genSuccessResult(menuService.enableOrDisable(menuCode));
    }

    @Log(title = "系统菜单表", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryMenuListAndParentMenu")
    public Result queryMenuListAndParentMenu(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "menuCode", value = "菜单编码") @RequestParam(required = false) String menuCode,
            @ApiParam(name = "isAll", value = "是否查询全部 0-否，1-是") @RequestParam(defaultValue = "0") String isAll,
            @ApiParam(name = "sysType", value = "系统类型") @RequestParam(defaultValue = "1") String sysType) {
        return ResultGenerator.genSuccessResult(menuService.queryMenuListAndParentMenu(searchParam, isAll,menuCode,sysType));
    }
}
